from models.models_dev import OpOrderGoods as DevOpOrderGoods
from models.models_prod import OpOrderGoods as ProdOpOrderGoods
from services.base_dev_common_service import BaseDevCommonService
from utils.log_utils import get_logger
from utils.obj_utils import ObjectUtil

# 获取一个命名的日志记录器
logger = get_logger(__name__)


class DevOrderGoodsService(BaseDevCommonService):
    def __init__(self):
        super().__init__(model_class=DevOpOrderGoods, time_field='order_created_time')

    def add(self, order_goods: list[ProdOpOrderGoods], session=None):
        # 如果未提供session，则获取新的session
        if session is None:
            session = self.get_session()
        # sku_maps = order_goods_sku_map([order.outer_id for order in order_goods])
        test_order_goods_ls = []
        for order_good in order_goods:
            test_order_goods = DevOpOrderGoods()
            ObjectUtil.copy_fields(test_order_goods, order_good, self.get_table_fields({'id', 'order_created_timestamp'}))
            test_order_goods_ls.append(test_order_goods)
        session.add_all(test_order_goods_ls)
        session.commit()
